package com.kcwl.carrier.application.service;

import com.kcwl.carrier.application.command.OperateLogCommand;
import com.kcwl.carrier.domain.entity.OperateLog;
import com.kcwl.carrier.domain.service.OperateLogDomainService;
import com.kcwl.carrier.interfaces.dto.OperateLogDTO;
import com.kcwl.carrier.interfaces.enums.OperateLogTypeEnum;
import com.kcwl.carrier.interfaces.query.OperateLogQuery;
import com.kcwl.framework.utils.KcBeanConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 刘旭超
 * @date 2022年12月08日 11:32
 * @Description
 */
@Service
public class OperateLogApplicationService {
    @Autowired
    private OperateLogDomainService operateLogDomainService;

    public List<OperateLogDTO> queryLog(OperateLogQuery operateLogQuery) {
        List<OperateLog> operateLogs = operateLogDomainService.queryLog(operateLogQuery);
        List<OperateLogDTO> result = KcBeanConverter.toList(operateLogs, OperateLogDTO.class);
        return result;
    }

    /***
     * 插入Log
     * @param operateLogCommand
     */
    public void insertLog(OperateLogCommand operateLogCommand) {
        OperateLog operateLog = KcBeanConverter.toBean(operateLogCommand, OperateLog.class);
        operateLog.setSubmitTime(new Date());
        operateLogDomainService.insertLog(operateLog);
    }

    /**
     * 司机再次提交认证信息日志
     *
     * @param carrierId
     * @param mobile
     */
    public void reAuthCarrierLog(Long carrierId, String mobile) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(1);
        operateLogCommand.setCarrierId(carrierId);
        operateLogCommand.setAction("再次提交");
        operateLogCommand.setAuditorId(carrierId);
        operateLogCommand.setMobile(mobile);
        insertLog(operateLogCommand);
    }

    /**
     * 司机提交认证信息日志
     *
     * @param carrierId
     * @param mobile
     */
    public void registCarrierLog(Long carrierId, String mobile, Date createDate) {
        OperateLog operateLog = new OperateLog();
        operateLog.setType(1);
        operateLog.setCarrierId(carrierId);
        operateLog.setAction("提交认证");
        operateLog.setAuditorId(carrierId);
        operateLog.setMobile(mobile);
        operateLog.setSubmitTime(createDate);
        operateLogDomainService.insertLog(operateLog);
    }

    /**
     * 更新司机信息日志
     *
     * @param carrierId
     * @param authUserId
     */
    public void updateCarrierLog(Long carrierId, Long authUserId) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(1);
        operateLogCommand.setCarrierId(carrierId);
        operateLogCommand.setAction("更新");
        operateLogCommand.setAuditorId(authUserId);
        insertLog(operateLogCommand);
    }

    /**
     * 客服驳回司机认证日志
     *
     * @param carrierId
     * @param authUserId
     */
    public void rejectCarrierLog(Long carrierId, Long authUserId) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(1);
        operateLogCommand.setCarrierId(carrierId);
        operateLogCommand.setAction("客服驳回");
        operateLogCommand.setAuditorId(authUserId);
        insertLog(operateLogCommand);
    }

    /**
     * 客服通过司机认证日志
     *
     * @param carrierId
     * @param authUserId
     */
    public void passCarrierLog(Long carrierId, Long authUserId) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(1);
        operateLogCommand.setCarrierId(carrierId);
        operateLogCommand.setAction("客服通过");
        operateLogCommand.setAuditorId(authUserId);
        insertLog(operateLogCommand);
    }

    /**
     * 客服通过车辆认证日志
     *
     * @param vehicleId
     * @param authUserId
     */
    public void passVehicleLog(Long vehicleId, Long authUserId, String remark) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(OperateLogTypeEnum.VEHICLE_LOG.getType());
        operateLogCommand.setVehicleId(vehicleId);
        operateLogCommand.setAction("客服通过");
        operateLogCommand.setAuditorId(authUserId);
        operateLogCommand.setRemark(remark);
        insertLog(operateLogCommand);
    }

    /**
     * 客服驳回车辆认证日志
     *
     * @param vehicleId
     * @param authUserId
     */
    public void rejectVehicleLog(Long vehicleId, Long authUserId, String remark) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(OperateLogTypeEnum.VEHICLE_LOG.getType());
        operateLogCommand.setVehicleId(vehicleId);
        operateLogCommand.setAction("客服驳回");
        operateLogCommand.setAuditorId(authUserId);
        operateLogCommand.setRemark(remark);
        insertLog(operateLogCommand);
    }

    /**
     * 更新车辆信息日志
     *
     * @param vehicleId
     * @param authUserId
     */
    public void updateVehicleLog(Long vehicleId, Long authUserId, String action, String remark) {
        OperateLogCommand operateLogCommand = new OperateLogCommand();
        operateLogCommand.setType(OperateLogTypeEnum.VEHICLE_LOG.getType());
        operateLogCommand.setVehicleId(vehicleId);
        operateLogCommand.setAction(action);
        operateLogCommand.setAuditorId(authUserId);
        operateLogCommand.setRemark(remark);
        insertLog(operateLogCommand);
    }

    /**
     * 司机提交认证信息日志
     *
     * @param vehicleId
     * @param authUserId
     */
    public void registVehicleLog(Long vehicleId, Long authUserId) {
        OperateLog operateLog = new OperateLog();
        operateLog.setType(OperateLogTypeEnum.VEHICLE_LOG.getType());
        operateLog.setVehicleId(vehicleId);
        operateLog.setAction("提交认证");
        operateLog.setAuditorId(authUserId);
        operateLogDomainService.insertLog(operateLog);
    }

    /**
     * 司机撤销驳回信息日志
     *
     * @param vehicleId
     * @param authUserId
     */
    public void cancelRejectLog(Long vehicleId, Long authUserId) {
        OperateLog operateLog = new OperateLog();
        operateLog.setType(OperateLogTypeEnum.VEHICLE_LOG.getType());
        operateLog.setVehicleId(vehicleId);
        operateLog.setAction("撤销驳回");
        operateLog.setAuditorId(authUserId);
        operateLogDomainService.insertLog(operateLog);
    }

}
